package com.scott.ch130;

import com.scott.ch130.entity.Baby;
import com.scott.ch130.entity.Child;
import com.scott.ch130.entity.Parent;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

/**
 * @author 黄后林
 * @version 1.0
 * @note
 * @date 2021-12-18 23:12:54
 */
public class Client {

    public static void main(String[] args) {

        List<Parent> parents  = new ArrayList<>();
        parents.add(new Parent());

        List<Child>  children = new ArrayList<>();
        children.add(new Child());

        List<Baby>   babies   = new ArrayList<>();
        babies.add(new Baby());

        // 放开注释就会报错哦 因为泛型统配符的上限是Child
        // print(parents);
        print(children);
        print(babies);

    }


    public static  void print(List<? extends Child> list){
        // 使用泛型统配符的上限后、集合中不能再添加元素
        // list.add(new Baby());

        for (Child child : list) {
            System.out.println(child.getName());
        }

    }
}
